package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseManagerController {

    private ManagerService managerService;

    @Autowired
    public BaseManagerController(ManagerService managerService) {
        this.managerService = managerService;
    }

    // 根据属性 ID 查询属性值集合
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId) {
        BaseAttrInfo baseAttrInfo = this.managerService.getAttrInfo(attrId);
        List<BaseAttrValue> list = baseAttrInfo.getAttrValueList();
        return Result.ok(list);
    }

    // 新增和修改平台属性
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        this.managerService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }


    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1() {
        List<BaseCategory1> baseCategory1List = this.managerService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable Long category1Id) {
        List<BaseCategory2> baseCategory2List = this.managerService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable Long category2Id) {
        List<BaseCategory3> baseCategory3List = this.managerService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

    // 根据分类查询平台属性
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable Long category1Id, @PathVariable Long category2Id, @PathVariable Long category3Id) {
        List<BaseAttrInfo> list = this.managerService.attrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(list);
    }

}
